<!DOCTYPE html>
<html lang="zh-Hans-CN">
<head>
  <% include("/include/header3.html",{"title":"开发-站内消息"}){} %>
</head>
<body>
<div id="app" class="layui-fluid">

  <div class="layui-card">
    <div class="layui-card-body">
      <t-form :data="queryForm" label-width="calc(5em + 20px)" layout="inline" colon>
        <t-form-item label="消息标题">
          <t-input v-model="queryForm.title" placeholder="输入消息标题" clearable></t-input>
        </t-form-item>
        <t-form-item label="消息类型">
          <t-select v-model="queryForm.category" :loading="categoryOptions.loading" :options="categoryOptions.data" placeholder="选择消息类型" clearable></t-select>
        </t-form-item>
        <t-form-item label="消息状态">
          <t-select v-model="queryForm.status" :options="statusOptions" placeholder="选择消息状态" clearable></t-select>
        </t-form-item>
        <t-space align="center" breakLine>
          <t-button theme="primary" @click="queryData">
            <template #icon><i class="layui-icon layui-icon-search text-size-14 mr-10"></i></template>
            查询
          </t-button>
          <t-button theme="primary" @click="jumpEdit('')">
            <template #icon><i class="layui-icon layui-icon-add-1 text-size-14 mr-10"></i></template>
            新增
          </t-button>
        </t-space>
      </t-form>
    </div>
  </div>

  <div class="layui-card">
    <div class="layui-card-body">
      <t-table :columns="columns" :data="table.data" :loading="table.loading" bordered hover resizable>
        <template #loading>
          <div class="t-table--loading-message">加载数据中，请稍后...</div>
        </template>
      </t-table>
      <div class="pa-25 pb-15">
        <t-pagination v-model="queryForm.pageNumber" v-model:page-size="queryForm.pageSize" :total="table.totalRow" show-first-and-last-page-btn show-jumper
                      @change="queryData"></t-pagination>
      </div>
    </div>
  </div>
</div>

<script>
  const PATH_URL = "dev/message/";
</script>
<script>

  setupVue("#app", {
    setup() {

      // 查询表单
      const queryForm = Vue.reactive({ pageNumber: 1, pageSize: 10 });
      // 表格相关
      const table = useTable();
      const fetchData = window.reloadData = () => fetchPage(axiosGet, PATH_URL + "page", queryForm, table);
      const queryData = (info = {}) => {
        Vue.nextTick(() => {
          const { current = 1, pageSize } = info;
          queryForm.pageNumber = current;
          if (pageSize) queryForm.pageSize = pageSize;
          fetchData();
        })
      }
      init(() => {
        fetchData();
      });

      // 打开编辑窗口
      const jumpEdit = (id) => location.href = PATH_URL + "edit?id=" + id;

      // 删除
      const clickDelete = (row) => handleDelete(axiosDelete, PATH_URL + "delete", { id: row.id }, table, "确定删除【" + row.title + "】站内消息吗？", fetchData);

      // 状态选项
      const statusOptions = [{ label: "全部", value: "" }, { label: "发送", value: 1, theme: "success" }, { label: "暂存", value: 0, theme: "danger" }];

      // 消息类型
      const categoryOptions = useOptions();
      dictOptions({ columnField: "label,value", codeLike: "dev_message_category_" }, categoryOptions, true);

      // 表格列表显示
      const columns = [
        { colKey: 'serial-number', align: 'center', title: '序', width: "20px" },
        { colKey: 'title', title: '消息标题', align: 'center', width: '200px', ellipsis: true },
        { colKey: 'category', title: '消息类型', align: 'center', width: '80px' },
        {
          colKey: 'whole', title: '全部通知', align: 'center', width: '60px', cell: (h, { row }) => {
            return h(TDesign.Tag, { variant: 'light-outline', theme: 'default' }, row.whole === 1 ? '全部通知' : '用户通知');
          },
        },
        {
          colKey: 'status', title: '状态', align: 'center', width: '60px', cell: (h, { row }) => {
            const status = statusOptions.find(item => item.value === row.status);
            if (status) {
              return h(TDesign.Tag, { variant: 'light-outline', theme: status.theme }, status.label)
            } else {
              return h(TDesign.Tag, { variant: 'light-outline', theme: 'danger' }, '未知状态')
            }
          },
        },
        { colKey: 'publishTime', title: '发送时间', align: 'center', width: '80px' },
        {
          title: '操作',
          align: 'center', width: '80px',
          cell: (h, { row }) => {
            return h(TDesign.Space, {}, [
              h(TDesign.Link, { theme: 'primary', onClick: () => jumpEdit(row.id) }, row.status === 0 ? '编辑' : '查看'),
              h(TDesign.Link, { theme: 'danger', onClick: () => clickDelete(row) }, '删除'),
            ]);
          },
        },
      ];

      return {
        queryForm,
        table, columns, queryData,
        jumpEdit,
        statusOptions, categoryOptions,
      }
    },
  });
</script>


</body>
</html>
